Slightly improved memory management