added proper closure over req and res in logAndSendError