Write more tests, refactor index