Improve root mean square, fix tests