several improvements and fixes