Refactored and removed redundant code