Added debug mode, fixed templates.