add environment variable to debug to console
Remove unused and broken function
Add "groups" support which (for now) affects only sorting. Update sorting methods to remove redundancy, centralize all logic in one place.