AUTO-576 refactored a bit so duplicate code is not used