changes to tag logic and adding mem
fixing/simplifying table aggregation logic