encapsulated example in function