Updated middleware to not crash on 404