Refactor to remove redundant code