A few clean ups and also tested, its working fine