Refactored user management code