Made the algorythm faster, committed the if check