Added more input validation