Improved graph efficiency and added a resample function