Implement suggestions from @ukd1 and @smathieu