added ecoding and decoding functions for rules and words