consolidated duplicate code