Bug 11630: (QA Followup) Move code to subroutine, add unit tests