Refactored and consolidated