fix #73 didn't reformulate query for the choosing newvalid ID loop
fix issue #74
fixed #75
fix #75
minor SQL correction for empty value syntax using NULL