More code cleanup and commenting