Code cleanup phase 2