refactor, extract codes to method