Suggestion

Played with it ~15 minutes, dunno if any good. Here is a diff that you can look at or merge.