First working version
For some limited meaning of "working", anyway