cleanup and function fix