Optimised for iOS 8 and fixed a bug