fixed bugs with db connection