refactor of Provider, add tests