Not so pretty fix.
Removed reference query.
Added .*
Helper to calculate distances