Code cleanup and unification