Fix computations due to indexing errors

Passes test suite

Fixes #15, Fixes #21, Fixes #23