Refactor: Removed more duplication in the code