Sync with Bernt Hansen's changes