code cleanup, self review and documentation