test improvements and bug fixes