Fixes for multi-instance support

- Ensure we sequence everything correctly
- Use correct variables in templates