improvements to rsquare (it was a bit ugly)