Changed concurrency logic.
Debugged and changed some functions.
Added some functions and tests.