Added new test
Refactored code