When posting code samples that illustrate a problem, it is always a good idea to follow the principle of "Minimal yet Complete".

Minimal means that the problem has been reduced to the absolute...