Fix memory corruption error