Fixing $badpair SQL statements
Tweaking a few details