Added method for validating the input
Better validating method