Code cleanup and performance