I think even though this may not be exactly the concept you are talking about, this might help you to understand how it should work.
Once you have that mastered then look at