Separated API from app.

This is the first step towards a complete separation of the API from the rest of the app. This is to let others use just the API without having to deal with the webpage stuff.