Clean up code and move common funcs to ScriptRenderer