Created tests and refactored code