various improvements and bug fixes