fixed OSErro 17 bug following http://stackoverflow.com/a/12468091/1063612