Fixed tons of bugs & added max plugisn to test

Tons of bugs related with threads was fixed. The option "--max" was
added.