Refactored for readability and cleaned up unused gems