parameter tuning. patch is made by @KeenS.