code optimization and fixes

code optimization and fixes
+ optimization of code
+ cleaning of code
+ fixed some issues with tracking class