consolidating duplicate code