Fix #4246 and #4244

I tested this with Python 2.7.8 and Python 3.4.1 on Windows 7