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