Merge AHL changes

Improvements and fixes which were kindly allowed to be brought back upstream into open source realm by AHL.