Refactored some code for better readability.