Refactored try except placement to eliminate redundancy.