Clean up code. Fix memory leaks.