memory bugfixes