use a context

use with self.do_half instead of halving and doubling each time.
use tuples
lose the lambdas
merge commit