There's an apple implementation of this now.