refactor
Fixed some bugs