added encode and decode