clean up and a little memory management