Fixed #7
And another issue discovered in the process.