Updated to make sure it works in the best case