fixing database coonnection close
improved insert