Reintegrate changes from mlafeldt