Refactor query_transform with implicit context