Refactor all the things. Write more tests