Add additional safety check for IsPowerOf method