refactore code