refactored out some repetitions