cleaned up logic for graph drawing