Major improvements. Specially in template.php