This was caused by precision loss due to using uint8. The cast to int64 was occurring in the wrong location. Fixes #145.