Fixed sqrt < 0 problem