refactor and run tests