Refactored code for workability