cleaning and pruning
moved helper functions to replace loc module