move 404 code into a function