combine some code into a function