added new tests and refactored code