Lots of little edge case fixes, tested and approved