Fixed issues stated in batch 2 and made code modular.