changed functions from C++ to Objective-C