took out some code repetition