fixed all memory bugs for now. Tests dont work yet