sync with upstream and add afew fixes