Port rails 3.1 changes to 3.2