Add chunk markers and refactor scripts