Refactored some code to reduce classe size.