index template, and cleanup functions