buggy refactored code