Refactor targetDocument processing in prepareQueryElement()

More object calisthenic improvements.