Further refactoring + added a few more tests