Some bug fixes

Some bug fixes