lots of improvements and fixes (a hodgepodge, sorry)