Refactored with better practices