Optimizing, works in more cases