Code reoganisation -- global variables, functions, code