minor code improvements and comments