Code cleanup and improvements.