update some code to reduce cyclomatic complexity of the overall file