Bug fixes, missing str and checking length of file opened with w
mode.