Refactor, avoid duplicate code