Updated Objective-C implementation.