Improving code snippet