added encap function