Refactored and removed redundant codes