Added uniq function & test; cleaned up code somewhat