refactor connection code and add group dao