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

This is basically PR #330 with passing specs.
This file should never be changed manually. Read the file header.