Add unwrapIfNeeded and use it in a few places.

Fixes #143