more optimize
add c++ implement