Fixed several bugs

fixed several bugs