added more input validation