fix function call and cleanup