fixed variable elimination and cleaned it up a bit