Fix issue: 'len' referenced before assignment

The error is caused by the built-in function `len` used in the
new-added code in #124.

Changed the original `len` variable to `msglen` to avoid name
conflict.

Also removed a useless semicolon in the code.