Improved user management code