Revert "Revert "Cleanup and fix CAF SSN handling code.""

This reverts commit 24a4849d28ca3088d257049038785128dfd22614.