Refactored some code around.