added Darwin-specific changes from Marcus Chang