Some bug fixes