A revised version of PR #330 that passes all specs.

This is basically PR #330 with passing specs.
Please do not change this line, I don't want to use a RSpec-specific syntax here.