reducing code duplication

This code was duplicated inside both if/else.
No logic change made.