Fix functions.sql problems

Fixed infinite loop caused by last chance/all chances being 0 in pMain (Open issue by massl)
Fixed syntax error in pCleanupOOB conversion checks