"I've updated the code to make it more clear."
You've added, modified and deleted code from your original post (OP).
This potentially renders responses to your OP either meaningless or, at best, confusing.
An example of how to update a post is contained in my original response.
Please read "How do I change/delete my post?".
"Also, would your example work with threads?"
Why wouldn't it? What did you try? What problems did you encounter?
Please read "How do I post a question effectively?".
| [reply] |