move clean up code to a function