Work on bad accesses and then memory leaks.

These were not declared in this context before.