Clean up
Mako optimizations (credits to ctfrommn)