refactoring, added error 500 and timeout