moved javascript to avoid flicker