some pilfering from @pengwynn