Refactor and divide in methods to reduce cyclomatic complexity
reduce cyclomatic complexity