Code cleanup and formatting