removed more globals, fixed seed and main loop functions