free memory bugfix