several bugs fixed

Fixed several bugs