Fixed some meory errors