Refactored the code. Provided details in README file.