Add more tests + minor refactoring