added query input validation