These same 3 lines are duplicated lines 637-639. These should be factored into a new function.