refactor  the code