Code from Duration demo http://vimeo.com/59654979