Working riot.js implementation, a little messy