refactored functions.
added tests for encode_l.