cleared from dirty code and put some comments