Improvments after @andymckay's code review