reworking the logic because it was too complex