Cleanup of functions and criterion