added 500 error handling