refactors and tests