added tests and refactored some stuff