copy of code from my blog addapted for c9 environment