This was duplicated everywhere so I just moved it to one function. Signed-off-by: Waqar Ahmed <waqar.17a@gmail.com>