fixes #6760 Remove the last query, partial revert of original implementation59925362d527fbd051a4e12113abcab282983436