Code cleanup and fix build