making the code DRY and consistent