Fix some performance issues