Better coverage and some refactoring