Restored the check_template function