adaptation of Bill Gathen's sinatra code