Refactor snippet rewriting and compilation result packaging code