Improving code as suggested