refactoring code to check validate user