comments and minor code improvements