add tests and fix major brokeness