Fix cert checking in iOS 6 and some general cleanup.