Optimizations, fixes, and preparation for testing