Removed leftover duplicated code
Refactored to isolate function