implemented stuff, fixed bugs, repaired memory leak, changed to use no globals