[Magic-HD] Better use of templates & some code clean up.