Some bug fixes, minor changes