Refactored code & test