Rewrite scripts on runtime, cleanup code