modified var names to respect C++ standards
fixed maaaaany bugs, some improvements