modified version for MacOS