Refactored for better organization