fixed error handling for dangling else