improve code for mac build