remove duplicated code, fixes #3362

rebased to actual master, checked in dependency