Implemented select function, still need to improve c++ function