Refactors and test