Fixed some allocation bugs