Small bug fixes in memory manager