Small refactors and some testing