cleaned up code, added ability to close graph