changed logic slightly: