Refactored some redundant code