Changed to a more efficient implementation.