lots of tweaks, move to proper template system