Fixed issues with passing res.end into functions