Refined templates.js
Added upload middleware.