Remove dead code.
More robust Swift code.
Other minor changes.