Fixed a problem with RMS calculations and added some unit tests for them.