fixed some stuff, debugging memory problem