Added Exception Handling and Made pep8 compatible
Slight Code Modification