a few performance and bug fixes