Code cleanup and warning fixes