Rewrite main script