Remove bugs and upgrade buffer
make compatibily with C++11