function and rfunction cleanup