First version of full working code with graphs.