Cleaned up template.php