reduce cyclomatic complexity & duplicated code