Improving elegance of earlier code