Fixed memory problems