code refactoring and example update