Feature #2971: Refactor and minor fix