Fixed memory leaks and added graph struct