There are strangely placed $before_title
and $after_title;
variables, wrapping around the main content of the widget. This will likely result in the div being wrapped in a heading tag in most themes.
Looks to me that
if ( $contents ) echo $before_title . $contents . $after_title;
should be replaced with:
if ( $contents ) echo $contents ;