Refactor, reduce duplicate code