naive variable elimination cleaned up