Fix some bug and make better timing