Added unique function detection. Fixed up bugs...