added tests, refactored a couple functions