Move more things to the api module and add more tests