Handle functional dependency right. Also fix empty input cases.
more empty-input fixes