Ported from iOS 8.0 to 7.1