added example and code refactor