A bit of renaming, and fixed potential resource leaks.