I've refactored this code about 8 times. Tried several methods. What am I missing?