Clean things up a bit and remove some loops