Simplify a bit and better document the code.