improve logic