numerous improvements and fixes