refactor and running tests