refactor and additional tests