Added input validation