Refactor the web api

This will resolve #31