implemented hierarchical in both encode and decode functions