Fixing broken OS X behaviour and adding test.