further work on #56 - makes things a bit more generic