working version from 2011, some features broken as of 2014