Refactor for less duplicate code