improve pipe logic