Fixed memory errors and removed unused debug.