   .get (req, res) ->
     Template.find (err, files) ->
       if err
-        res.send err, 500
+        res.send 500, err
       else
         res.send files
 
   .post (req, res) ->
     Template.write req.body.filename, req.body.contents, (err) ->
       if err
-        res.send err, 500
+        res.send 500, err
       else
-        res.send {}, 201
+        res.send 201, {}
 
 app.route('/templates/:filename')
   .get (req, res) ->
     Template.read req.params.filename, (err, contents) ->
       if err
-        if err.code == 'ENOENT'
-          res.send err, 404
+        if err.code is 'ENOENT'
+          res.send 404, err
         else
-          res.send err, 500
+          res.send 500, err
       else
         res.send filename: req.params.filename, contents: contents
 

  .put (req, res) ->
    Template.write [req.params.filename, req.body.filename], req.body.contents, (err) ->
      if err
        res.send err, 500
      else
        res.send {}, 201

    return res.send 400, {error: 'Can’t mess with the index yet.'} if req.params.filename is 'index'
    Template.remove req.params.filename, (err) ->
      if err
        res.send 500, err
      else
        res.send 204

