cleanup and function extractions