Create a theme function for form fields
I think one of your problem is with this:

$element = &amp;$variables['element'];


I don't think you can assign a reference to an array element (the &amp;), so try changing it to:

$element = $variables['element'];


and I don't see a 'element' element, so unless I'm blind you're trying to access an element that isn't there, so it will always return NULL;