cherry-pick and merge codio's changes

more to come