refactoring code separe db and user management