clean up some code duplication