Re-merges pull request #453.

Original commits:

  21f1549
  ae89356
  8ed523e
  039cfaa