Lots of fixes, optimizations and other work to finish the transfer to Rails.