refactored register to db