remove static variables from main

and clean up a bit