Improving 404 lookup logic