Rewrite Ex5.1 and minor fixes to Ex5.2