various improvements and fixes