Fixed some "Trying to get property of non-object" errors