Improvements in the code, removal of excessive tabs, pep8fy and fixed bad logic