fix bad and inefficient patterns