modified header/template function sql and header.py