Some memory related bug-fixes.