refactor graph drawing