Refactoring and unit tests for windows.psm1