refactored to meet maxstatements rule