Refacto to remove duplicate code