Some bug fixes due to failed tests