Added a security check in the query function.