Refactoring of graphing logic