Fixed exception handling so all exceptions are only caught once.