Documented and cleaned up a bit.