Refactored code
Added tests