Code cleanup and format