Fix bugs exposed by examples