First working version, tested on OSX