Added square roots.
+ bug fixes and cleanup.