trying to remove duplicate code