Partial CodeMaid cleanup.
Tidied up record reading code, fixed mem leaks.