Fixed duplication issue
Minor bugs fixed, also cleaned up the anti-duplication code