Changed query testing. Also set system exit codes to 1 (error) to indicate abnormal termination.