Update code style and fixed bugs in examples