change register function, and add db operations