all sorts of compatibility improvements and fixes