added some helper functions, fixed GM, added threshold for edges to GM