move code out of function into function where it is used