Removed ambiguious call to sqrt (discovered on Apple).
Fixed shadowing.