You're showing us badly formatted code, of which you aren't sure it's right. You also describe what you have (although that doesn't seem to match the code). But you aren't saying what you want to achieve.
So, how do you expect to get a useful answer?