consolidated some function dealing with sessions and db