[Tests/Lib] Additional unit tests, some fixes for bugs and improvements.