First working code (some in progress!)