Major refactoring to support new keystore modes. Some functionality removed (package removal).