Lots of bug fixes. WIP.