Stage 3: Add support for templated waits.
This commit has several fixes in it. The overall fix is introducing a feature to recognize templated waits. This is when the class has a template type, say D1, and the wait() uses it as an argument such as wait(D1). The commit works in a way where both non-templated and templated type use the same WaitContainer class.