fixed error handler on line 23 to prevent premature exit