dir structure tidied up and all global vars and functions wrapped in graph object