Rename confusing variable lookup to code
Optimize assign_codes() and add tracing code
Code length counts don't need to be global
Rewrite cost computation code
Wrap lines which exceed 80 characters