Updated code to match review

Thanks to @graemechristie for his review of #21, here are the changes to
the powershell version.