Refactored $gid code
Moved to JEMHelper