Added 500 error handling.