more changes. It is almost fixed and completely written in C++11