Mac compatibility fixes (patch by Benjamin Seppke)