Assorted bug fixes