Fix issues with tests

This pull request fixes many issues with tests, especially gathering errors from subshells wunning in background. I've described everything in commit messages.