Backport a few fixes from default branch to 0.1.

This includes the following revisions:
 * f91d3a18db7b
 * dbe7a578af42
 * 95545a36ed0e
 * 7806af1b171a
 * cacc8353b5c2