Adding validation for query and fixing bug on the keyword print