Refactored for compatibility with flash fallback.