Modified for OS X (BSD) compatibility