moved call to DB after checking inputs - faster

to make the check of inputs faster, I mover connection code after it.