Fix index issues

Fixes #162, #126, #42

Will merge this in a sec :)