Added some exception catching.