New general function for tests; tests refactoring; cleaning