Moved functions from template.php