Partial fixes for UTF-8 command line handling related to issue #20, with come use of encoding and tidying the logic in some places