Fix global-to-local indexing and local-to-global indexing.

See gh-issue #154
Test for gh-issue #154