lots of fixes and special cases