started refactor and tests