Cross-posted on CodeGuru.