more cleanup and moved some utilitiy functions to the proper libraries