$language variable causes a lot of notices as non-object
For your issues you can refer 

these links have given some patch for these notices 


https://www.drupal.org/node/1907684
https://www.drupal.org/node/1104822 
https://www.drupal.org/node/1853170