Some code cleanup and commenting