a few improvements and bug fixes