A number of new functions and cleanup