document functions and cleanup