re-implementation of quash in c++