thanks to astroshim, fix two bugs here