A number of bug fixes

See fogbugz for details