Refactored code
Amended code (minor)