Some bug fixes and changes