Add try, catch exception and clean code for pep8