First working version. I think.
It's late.