properly handle 404 and 500