Improvements suggested by @otfrom