do some refact
fixed some bugs