Localised a few variables, no longer needed as globals.