lots of fixes here and there