Fixed some possible Exceptions and connection failures.