Refactorings and test additions