Fixed allocation bugs, still pending invalid memory operations