modified code so that everything is now mostly namespaced to avoid global variables