Code cleanup and efficiency tweaks.