Method and apparatus for variable length coding