diff -u nlib_2/compatibility_utils.py nlib/compatibility_utils.py
--- nlib_2/compatibility_utils.py	Tue Oct  7 16:19:28 2014
+++ nlib/compatibility_utils.py	Wed Oct  8 21:13:35 2014
@@ -4,25 +4,25 @@
 
 # Copyright (c) 2014 Kevin B. Hendricks, John Schember, and Doug Massay
 # All rights reserved.
-# 
-# Redistribution and use in source and binary forms, with or without modification, 
+#
+# Redistribution and use in source and binary forms, with or without modification,
 # are permitted provided that the following conditions are met:
 #
 # 1. Redistributions of source code must retain the above copyright notice, this list of
 # conditions and the following disclaimer.
-# 
+#
 # 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials 
+# of conditions and the following disclaimer in the documentation and/or other materials
 # provided with the distribution.
 #
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
-# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
-# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
+# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 # WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 from __future__ import unicode_literals, division, absolute_import, print_function
@@ -50,14 +50,14 @@
     range = xrange
     text_type = unicode
     binary_type = str
-    # if will be printing unicode under python 2 need to protect    
+    # if will be printing unicode under python 2 need to protect
     # against sys.stdout.encoding being None stupidly forcing forcing ascii encoding of unicode
     # sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
     # alternatively set environment variable as follows **before** launching python:  export PYTHONIOENCODING=UTF-8
 
 
-# NOTE: Python 3 is completely broken when accessing single bytes in bytes strings 
-# (and they amazingly claim by design and no bug!) 
+# NOTE: Python 3 is completely broken when accessing single bytes in bytes strings
+# (and they amazingly claim by design and no bug!)
 
 # To illustrate: this works for unicode in Python 3 and for all Python 2.X for both bytestrings and unicode
 # >>> o = '123456789'
@@ -77,14 +77,14 @@
 # >>> type(o)
 # <class 'bytes'>
 
-# This mind boggling  behaviour also happens when indexing a bytestring and/or 
-# iteratoring over a bytestring.  In other words it will return an int but not 
+# This mind boggling  behaviour also happens when indexing a bytestring and/or
+# iteratoring over a bytestring.  In other words it will return an int but not
 # the byte itself!!!!!!!
 
 # The only way to access a single byte as a byte in bytestring and get the byte in both
-# Python 2 and Python 3 is to use a slice 
+# Python 2 and Python 3 is to use a slice
 
-# This problem is so common there are horrible hacks floating around the net to **try** 
+# This problem is so common there are horrible hacks floating around the net to **try**
 # to work around it, so that code that works on both Python 2 and Python 3 is possible.
 
 # So in order to write code that works on both Python 2 and Python 3
@@ -94,7 +94,7 @@
 
 
 if PY3:
-   # Also Note: if decode a bytestring using 'latin-1' (or any other full range 0-255 encoding) 
+   # Also Note: if decode a bytestring using 'latin-1' (or any other full range 0-255 encoding)
    # in place of ascii you will get a byte value to half-word or integer value
    # one-to-one mapping (in the 0 - 255 range)
 
@@ -112,7 +112,7 @@
 
     def bchar(s):
        return bytes([s])
-    
+
 
 else:
     def bchr(s):
@@ -152,17 +152,17 @@
 
 # In Python 3 you can no longer use .encode('hex') on a bytestring
 # instead use the following on both platforms
-import binascii 
+import binascii
 def hexlify(bdata):
     return (binascii.hexlify(bdata)).decode('ascii')
 
 
 # If you: import struct
-# Note:  struct pack, unpack, unpack_from all *require* bytestring format 
+# Note:  struct pack, unpack, unpack_from all *require* bytestring format
 # data all the way up to at least Python 2.7.5, Python 3 is okay with either
 
 # If you: import re
-# note: Python 3 "re" requires the pattern to be the exact same type as the data to be 
+# note: Python 3 "re" requires the pattern to be the exact same type as the data to be
 # searched ... but u"" is not allowed for the pattern itself only b""
 # Python 2.X allows the pattern to be any type and converts it to match the data
 # and returns the same type as the data
@@ -215,14 +215,37 @@
 # ie. To get  sys.argv arguments and properly encode them as unicode
 
 def unicode_argv():
-    global _iswindows
+    global _iswindows  # FIXME: Is iswindows correct?
     global PY3
     if PY3:
         return sys.argv
     if iswindows:
+
+        # Conversion of argv to unicode without using cdll.kernel32.GetCommandLineW
+        FILE_SYSTEM_ENCODING = sys.getfilesystemencoding()
+        uargv = []
+        in_double_quotations = False
+        for arg in sys.argv:
+            if not isinstance(arg, unicode):
+                arg = arg.decode(FILE_SYSTEM_ENCODING)
+            if in_double_quotations:
+                if arg[-1] == u'"':
+                    in_double_quotations = False
+                    arg = arg[:-1]
+                uargv[-1] = uargv[-1] + u' ' + arg
+            else:
+                if arg[0] == u'"':
+                    arg = arg[1:]
+                    if arg[-1] == u'"':
+                        arg = arg[:-1]
+                    else:
+                        in_double_quotations = True
+                uargv.append(arg)
+        return uargv
+
         # Versions 2.x of Python don't support Unicode in sys.argv on
         # Windows, with the underlying Windows API instead replacing multi-byte
-        # characters with '?'.  So use shell32.GetCommandLineArgvW to get sys.argv 
+        # characters with '?'.  So use shell32.GetCommandLineArgvW to get sys.argv
         # as a list of Unicode strings
         from ctypes import POINTER, byref, cdll, c_int, windll
         from ctypes.wintypes import LPCWSTR, LPWSTR
diff -u nlib_2/kindleunpack.py nlib/kindleunpack.py
--- nlib_2/kindleunpack.py	Tue Oct  7 16:19:28 2014
+++ nlib/kindleunpack.py	Wed Oct  8 21:55:34 2014
@@ -4,8 +4,15 @@
 
 from __future__ import unicode_literals, division, absolute_import, print_function
 
-import sys
+import sys, locale
 import codecs
+# Belows are needed on widnows running in cp932.
+# Although the reason is uncertain, it had worked without it for a while.
+if sys.version_info[0] == 2:
+    reload(sys)
+    sys.setdefaultencoding('utf-8')
+
+
 import traceback
 
 from compatibility_utils import PY2, text_type, utf8_str, unicode_str
@@ -160,8 +167,8 @@
 """ The section data that divides K8 mobi ebooks. """
 
 import os
-import locale
-import codecs
+#import locale
+#import codecs
 
 import array, struct, re, imghdr, zlib, zipfile, datetime
 import getopt
@@ -485,9 +492,10 @@
         seq, idtext = k8proc.getFragTblInfo(last_start)
         filename, idtext = k8proc.getIDTagByPosFid(toBase32(seq), '0000000000')
         linktgt = filename
+        idtext = unicode_str(idtext)
         if idtext != '':
             linktgt += '#' + idtext
-        guidetext += '<reference type="text" href="Text/%s" />\n' % linktgt
+        guidetext += utf8_str('<reference type="text" href="Text/%s" />\n' % linktgt)
 
     # if apnxfile is passed in use it for page map information
     if apnxfile is not None and pagemapproc is None:
@@ -538,7 +546,7 @@
         if cover_img is not None:
             if k8resc is None or not k8resc.hasSpine():
                 part = k8proc.getPart(0)
-                if part.find(cover_img) == -1:
+                if part.find(cover_img.encode('ascii')) == -1:
                     need_to_create_cover_page = True
             else:
                 if "coverpage" not in k8resc.spine_idrefs:
@@ -572,7 +580,7 @@
                 f.write(flowpart)
 
     # create the opf
-    opf = OPFProcessor(files, metadata.copy(), fileinfo, imgnames, True, mh, usedmap, 
+    opf = OPFProcessor(files, metadata.copy(), fileinfo, imgnames, True, mh, usedmap,
                        pagemapxml=pagemapxml, guidetext=guidetext, k8resc=k8resc, epubver=epubver)
     uuid = opf.writeOPF(bool(obfuscate_data))
 
diff -u nlib_2/mobi_html.py nlib/mobi_html.py
--- nlib_2/mobi_html.py	Tue Oct  7 16:19:28 2014
+++ nlib/mobi_html.py	Wed Oct  8 20:11:22 2014
@@ -79,7 +79,7 @@
         # put in the hrefs
         print("Insert hrefs into html")
         # There doesn't seem to be a standard, so search as best as we can
-        
+
         link_pattern = re.compile(br'''<a([^>]*?)filepos=['"]{0,1}0*(\d+)['"]{0,1}([^>]*?)>''', re.IGNORECASE)
         srctext = link_pattern.sub(br'''<a\1href="#filepos\2"\3>''', srctext)
 
@@ -87,7 +87,7 @@
         print("Remove empty anchors from html")
         srctext = re.sub(br"<a\s*/>",br"", srctext)
         srctext = re.sub(br"<a\s*>\s*</a>",br"", srctext)
-        
+
         # convert image references
         print("Insert image references into html")
         # split string into image tag pieces and other pieces
@@ -192,7 +192,7 @@
                 tag = srcpieces[j]
                 if tag.startswith(b'<'):
                     srcpieces[j] = within_tag_AmznPageBreak_position_pattern.sub(
-                        lambda m:b' style="page-break-after:' + m.group(1) + '"', tag)
+                        lambda m:b' style="page-break-after:' + m.group(1) + b'"', tag)
             part = b"".join(srcpieces)
             parts[i] = part
 
@@ -234,7 +234,7 @@
                         imageNumber = fromBase32(m.group(1))
                         imageName = self.imgnames[imageNumber-1]
                         if imageName is not None:
-                            replacement = b'"../Images/' + imageName + b'"'
+                            replacement = b'"../Images/' + utf8_str(imageName) + b'"'
                             self.used[imageName] = 'used'
                             tag = img_index_pattern.sub(replacement, tag, 1)
                         else:
@@ -269,7 +269,7 @@
                     if fontName is None:
                         print("Error: Referenced font %s was not recognized as a valid font in %s" % (fontNumber, tag))
                     else:
-                        replacement = b'%s%s%s'%(osep, b'../Fonts/' + fontName, csep)
+                        replacement = utf8_str('%s%s%s' % (osep, '../Fonts/' + fontName, csep))
                         tag = font_index_pattern.sub(replacement, tag, 1)
                         self.used[fontName] = 'used'
 
@@ -278,7 +278,7 @@
                 for m in url_css_index_pattern.finditer(tag):
                     num = fromBase32(m.group(1))
                     [typ, fmt, pdir, fnm] = self.k8proc.getFlowInfo(num)
-                    replacement = b'"../' + pdir + b'/' + fnm + b'"'
+                    replacement = b'"../' + utf8_str(pdir) + b'/' + utf8_str(fnm) + b'"'
                     tag = url_css_index_pattern.sub(replacement, tag, 1)
                     self.used[fnm] = 'used'
 
@@ -333,7 +333,7 @@
                             flowpart = flows[num]
                             if fmt == b'inline':
                                 tag = flowpart
-                            else:
+                            elif pdir is not None and fnm is not None:
                                 replacement = b'"../' + utf8_str(pdir) + b'/' + utf8_str(fnm) + b'"'
                                 tag = flow_pattern.sub(replacement, tag, 1)
                                 self.used[fnm] = 'used'
diff -u nlib_2/mobi_utils.py nlib/mobi_utils.py
--- nlib_2/mobi_utils.py	Tue Oct  7 16:19:28 2014
+++ nlib/mobi_utils.py	Wed Oct  8 20:29:07 2014
@@ -20,7 +20,7 @@
 
 import re
 # note: re requites the pattern to be the exact same type as the data to be searched in python3
-# but u"" is not allowed for the pattern itself only b"" 
+# but u"" is not allowed for the pattern itself only b""
 
 import os, array
 from itertools import cycle
@@ -160,8 +160,8 @@
     return value
 
 
-# note: if decode a bytestring using 'latin-1' (or any other 0-255 encoding) 
-# in place of ascii you will get a byte to half-word or integer 
+# note: if decode a bytestring using 'latin-1' (or any other 0-255 encoding)
+# in place of ascii you will get a byte to half-word or integer
 # one to one mapping of values from 0 - 255
 
 def mangle_fonts(encryption_key, data):
