Adding some fixes/optimizations from the 1.5 codebase