refactor out some repetitive code