Working?

A first go, it sort of works, but see bugs.