Fix some bug but have to optimize