Correcting possible infinite loop in power function