Updated code to make it work with iOS8.