add example for all functions, adjust structure and fix some bugs