Refactored some redundant code.