more memory management / bug fixes