add exception handling: code refactoring;