Cleaned up and organized JavaScript code.