more code cleanup and commenting