Fixed getOS function to be near-foolproof.