add function to free unused memory