Some functions ported from MyEPTools