refactore code with clean version