Wouldn't you know it? Reading this over I noticed a
hidden assumption in the code.
I am assuming you have only one package statement per file.
This isn't the safest, but it does reflect the way I almost
always do my code. Let me think for a few minutes and I may
post a fix.