Misc cleanup and utility functions added. Functionally nothing has changed