minor Refactor and  tests