consolidated some code into helper functions