Full rework. First working version.