fix some various bugs