Align the implementation with upstream Rails

This is getting really hard to maintain as is.
Merge pull request #75 from gsamokovarov/align-with-upstream-implementation

Align the implementation with upstream Rails