LILY-241: pep cleanup and smarter import of templates