fix some bad bugs and add an example