refactored & removed duplicate functions