Tests refactoring

Tests refactoring, code inspection, minor fixes;