added unit test, fixed lots of bugs. it is still buggy and about to change the indexing