Code cleanup and commenting improvements