merging this code with updates in a fork