Security Fixes and added template preprocessing