working implementation tested for Linux (Ubuntu) but should hopefully also be working for OS X