Work on bad accesses and then memory leaks.

I'll fix it tomorrow.