added tests and refactored a few things