Changed into a module.
Made more OOP.
Fixed corrupted record detection and handling