converted all objective-c to python (untested)