code cleaning, comments and minor optimization on lines 306 to 309