Fix bug in logic. Tests needed.