Initial refactor for userhandler DB functions
Fix errors