Refactor with helper function