Sorting keys in mem and some renaming