Added some exception handling to decrease crashes.