lots of fixes, cleanups, improvements