Refact, still need to check why cannot connect to db sometimes