Added exception handling to prevent a crash.