code updated as per review comment