first draft of the refactored code