Initial work

Looks functionally ok, but indentation and spaces are all over the place.