TWIN: Implement if functions better and some general scripting fixes