Lots of fixes, ready for testing!