Revert "Revert "Bug fixes and performance improvements""

This reverts commit 436466d75edb5f6fd848504d998f244426ea5a09.
5 files changed