Bug fixes and changes for PowerShell 2.0 compatibility