Added better 404 detection

This code still needs to be optimized.