add some functions for freeing resources