beta version of db code sort of working