Cleaning up code and memory leaks.