Fixed simple, but massive mistake in algorithm