style improvements and bug fixes