fixes to gcd and helper functions; everything seems to be in working order