some fix and add Mac OS X support