General code cleanup and commenting