Added square root to fix program and make more efficient