Refactored code to improve efficiency. Refactoring successful