Refactored more redundant code.