Fix flexible rails, Closes #944