fix js undefined arrays errors