correcting if statements to prevent Object.keys called on non object errors