added input validation