handle global variable $language not being set, restructure code a bit
Merge pull request #808 from dlobo/NoticeFixes

handle global variable $language not being set, restructure code a bit