Notwithstanding the fact that I bungled the code somewhere...what you call "my program" is effectively a translation of jdporter's program. Translated properly, it will return exactly the same results in exactly the same order. I've located my mistake and fixed.
Caution: Contents may have been coded under pressure.