More code cleanup, adding documentation.