fixed a bug when checking for invalid records