Code cleanup pass 1