Minor refactoring and typo fixing in tests