Add more tests, refactor a bit