move tag sql queries to function, change form field checking method