trying again to refactor to reduce boxing
refactored code to reduce boxing.