Input validation working well - code needs refactoring