do right encoding and decoding of AttributeSet
some minor refactorings