I have simplified this code. Thanks for pointing out.