Refactor javascript for better readability.