Stealing some more things from @ejfinneran