add error handling for cyclic graphs