consider moving this database part to a new function?