Several bugs fixed

several bugs fixed