Just another comity with a bit of cleanup. Parts left to be done with UI are marked by "~~~"