Performance improvements and bug fixes