Add more tests; refactoring