incorporating changes from old branch #535