Condensed Apple implementation a bit.