Code cleanup and fixed tests on non-windows systems