fix for issue #263; also replaced all sql statements and removed all trigger_error()'s