dbquery_insert() cleanup

Added debug mode and cleaned up code.