refactor so code isn't duplicated