refactoring the codes