Code cleanup based on analysis