implemented proper validation of input