Refactore code