Lots of refactoring.  Still need to get encryption working.