update to v3 api and some refactor in the process