Add RESTful API and make it a little more defensive