Force tags to lower case and remove duplicates, plus some bug fixes.