move db connect to early in the script