Refactored code

Refactored code.