some cleanup and a new function
some more cleanup