ERT-437: Moving code around to increase readability and reduce duplication.