Fixed vars
Removed debug code
Improved template