More work and fixes. Still wip.