Fixed bugs and now can be run multiple times without creating duplicate entries