Updated code to compile with MAC OS X