Some bug fixes in the current code