centralize some part of the codes and do cleaning