more improvements and bug fixes