initial base Misra-Gries code. not complete, but functional