implement @ahocevar's review/rewrite