Bigger patch, tests pass Windows & other platforms

See commit for details, passes on Windows 8, Ubuntu 12.04, Centos 6.4, FreeBSD 7.3