reorganised and added DB connection