Add session, template handling and fix the API