Fix ^w segfault and many bugfixes for macro scripting