Added extra exception handling.