Fixes a lot of issues with the new script

See commits for details