Refactored code use removed unnecessary code. Deduplicated code