Make some more things static and get rid of unnecessary local variables