Refactored code and optimized for mobile.