Convert from Objective-C from line 375 to the end