added graph for API, in dire need to clearn code up though