Imported a bunch of code from the deprecated Ratistics gem.