Dup bug fixed, still needs refactor
Refactor. Much more flexible now