Minor changes and added a few features. Also solved the issue of 'divide by zero'