What you posted is not fully tested, reusable code. What you posted is a question which clearly falls under the default category of "discussion/question".
When you created this thread, right above the area where you pasted your code was:
DO NOT post code with errors or known bugs. Code snippets must be fully tested, reusable code to share with others.
Clearly you found those instructions confusing. Would you care to suggest alternate instructions?