More commenting and some attempts at optimization.