Some code fixes and improvements.