Code is current a series of functions, but this should be a Class instead to avoid the use of global variables.