Refactored some code.