crazy rewrite, preserves script order now