Make commands.Query.compact tail-recursive