Added joins and fixed double declaration