many improvements and fixes