Tweak javascript to avoid null error