Working version of the encapsulation code
Working version of auto-encapsulation