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

See gh-issue #154
Test for gh-issue #154
Merge pull request #177 from cowlicks/global-to-local-fix

Fix global-to-local indexing (see gh-issue #154).