added more error checking to sql inserts