VG-1630: Added a function to de-duplicate code