added input validation loop