Refactoring in tests

This commit is also supposed to fix the test failures in @dastergon's recent PRs