Move 404 check to correct place