Improve error handling in user class