Removes duplicated variables; fixes #187 and fixes #186