Some bug fixes in the previous commit