Unify some code