Clean things up a bit and add logging