created some tests and refactored code