Fixed scope of local variable 'q'.