major changes, now should work as it was supposed
to in multithreaded environmnet