Stole ideas from zakwilson's fork. nurble func still needs a little work.
Fixed indention and refactored a bit, but still seems like there's a more idiomatic or straightforward way of doing this.