Hey monks I am not to be mis-understood over here as a person who wants to make his life complex.Actually I have some complex and confidential code that should not be posted.So I emulated the scenario with a simple yet to-the point code :)
I suspect you now have what you need. However if not then you need to give us a little more context.
We don't mind irrelevant details being omitted from a problem description - indeed we encourage it, but make sure you leave enough detail to allow us to help solve your actual problem. To that end it often helps to tell us something of the larger problem so we can help you find the most appropriate solution.