Lots of storage refactoring. Preparing for sync. New debug code.