Add some tests, refactor a little bit of api calls