refactor to consolidate the two methods