refactored example code