The Harder-Narasimhan stratication and Behrend's formula