Some bug fixes

Bug fixes