Updated the code for iOS8