Adds some test and refactorings