Completed port to macos

(Actually committed by Peter)