Fixed possible leak.
Reorganized some more code.